/*
This code explores the uptake of first round of PPP by firm size
*/

//Match rate for 941s

do "${dodir}/make_globals.do"

use "${datadir}/reg_data", clear

keep if yr == 2019

gcollapse (mean) num_employees forgivenessamount_first (sum) total_compensation med_wage, by(id yr)

//Matched at all in any quarter
gen ever_matched = forgivenessamount_first != .

gen num = 1

//Generate firm size bins 10 employees wide

keep if inrange(num_employees, 295, 705) 
gen firm_size = .
local bin = 0
forvalues bin = 295(10)695 {
	replace firm_size = `bin' + 5 if num_employees >= `bin' & num_employees < `bin' + 10
	local bin = `bin' + 1
}

//Collapse to allow options for weighted and unweighted

gcollapse (sum) match_wt=ever_matched num_wt=num (rawsum) match_raw=ever_matched num_raw=num [pw=num_employees], by(firm_size)


//Divide match over total to get take up rates
gen uptake_raw = round(100*(match_raw / num_raw), .1)
gen uptake_wt = round(100*(match_wt / num_wt), .1)


//Now do some plotting

line uptake_raw firm_size, /// 
	xtitle(Firm Size) xlabel(,nogrid) /// 
	xline(500) ///
	ytitle(% of Wage Payers) ylabel(,nogrid) /// 
	lcolor(navy)
	graph export $outdir/sum_stats/threshold_500.png, replace width(3000)

